import 'package:flutter/material.dart';
import 'package:flutter_deer/setting/models/version_entity.dart';
import 'package:flutter_deer/util/other_utils.dart';
import 'package:flutter_deer/widgets/state_layout.dart';
import 'package:package_info/package_info.dart';

class VersionProvider extends ChangeNotifier {

  StateType? _stateType = StateType.loading;
  StateType? get stateType => _stateType;
  VersionEntity? _version;
  VersionEntity? get version => _version;
  String? _currentVersion;
  String? get currentVersion => _currentVersion;
  bool? _needUpdate;
  bool? get needUpdate => _needUpdate;

  void setVersion(VersionEntity? entity) {
    PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
      this._currentVersion = packageInfo.version;
      _version = entity;
      if(this._currentVersion==_version!.versionNum.nullSafe){
        _needUpdate = false;
      }else{
        _needUpdate = true;
      }
      _stateType = StateType.empty;
      notifyListeners();
    });
  }
}
